package com.tsing.cli.system.config;

import com.tsing.cli.common.constant.FileConstants;
import jakarta.servlet.MultipartConfigElement;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.File;

/**
 * 临时目录配置类
 *
 * @author TheTsing
 */
@Configuration
public class MultipartConfig {

    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory multipartConfigFactory = new MultipartConfigFactory();
        File tempFile = new File(FileConstants.TEMP_FILE_PATH);
        if (!tempFile.exists()) {
            tempFile.mkdirs();
        }
        multipartConfigFactory.setLocation(FileConstants.TEMP_FILE_PATH);
        return multipartConfigFactory.createMultipartConfig();
    }

}
